<?php

namespace Home\Controller;

use MongoDB\Driver\Manager;
use Think\Controller;

class Index1Controller extends Controller {
    public function index() {
        $content  = $this->fetch("template/loanAgreement");
        $ancun    = new \Home\Service\AncunService();//A("Home/Ancun", "Service");
        $filename = '/usr/share/nginx/html/www/'  . time() . mt_rand(100000, 999999) . ".pdf";
        $filename = $ancun->savePdfFile($filename, $content);
        echo $filename;
        /* $map["itemKey"] = "itemKey";// 业务编号
         $map["flowNo"] = "flowNo";// 流程编号*/

        // 以下是保全的业务数据
        /* $data = array();
         $data["userName"] = "和智成";
         $data["identNo"] = "140931197503124192";
         $data["mobile"] = "18822269611";

         $map["preserveData"] = json_encode($data);

         $map["recordNo"] = "1184331919019397120583";//订单编号
         // 加盖投资方章(个人章)
         $map["needInvestor"] = "true";
         $map["investorIdcard"] = "seal_606_1511247524209";// 投资方证件号

         // 加盖借款方章(个人章)
         $map["needLender"] = "true";
         $map["lenderIdcard"] = "seal_606_1511247524209";// 借款方证件号*/
    }

    public function caPersonal() {
        // 个人信息
        $vid = I('vid');
//        var_dump($vid);die;
        $userdata = M('user','',C('DB'))->where(Array('vid'=>$vid))->field('truename,id_card,ctime,mobile')->find();
//        var_dump($vid);die;
        $map["isCaInterface"] = "true";// CA制章接口
        $map["userName"]      = $userdata['truename'];// 姓名
        $map["identNo"]       = $userdata['id_card'];// 身份证号
        $map["certType"]      = "7";// 证书类型：7场景证书
        $map["userType"]      = "1";// 用户类型：1个人
        //选填
        $map["sealLocation"] = "杭州市拱墅区泰嘉园";// 制章地理位置
        $map["sealResson"]   = "投资交易";// 制章原因
        $map["preserveData"] = json_encode($map);
        $ancun               = A("Home/Ancun", "Service");
        $ancun->setData($map);
        $data = $ancun->awardCaForPersonal();
        var_dump($data);
    }

    public function catest(){
        $vid = I('vid');
        $userdata = M('user','',C('DB'))->where(Array('vid'=>$vid))->field('truename,id_card,ctime,mobile')->find();
        $this->caPersonal($userdata['truename'],$userdata['id_card']);
    }
    public function cacompany() {
        // 个人信息
        $map["isCaInterface"] = "true";// CA制章接口
        $map["userName"]      = "温州易旅游网络科技有限公司";// 姓名
        $map["identNo"]       = "91330303MA285LWX6R";// 身份证号
        $map["certType"]      = "7";// 证书类型：7场景证书
        $map["userType"]      = "2";// 用户类型：1个人
        //选填
        $map["sealLocation"] = "温州市龙湾区蒲州街道文昌路209号C幢二楼D区09工位";// 制章地理位置
        $map["sealResson"]   = "权利声明";// 制章原因
        $map["preserveData"] = json_encode($map);
        $ancun               = A("Home/Ancun", "Service");
        $ancun->setData($map);
        $data = $ancun->awardCaForCompany();
        var_dump($data);
    }
    public function test(){
        $numbering = 'P2018153118542054996471w';
//        $numbering = I("numbering");
        $user['numbering'] =$numbering;
        $certificate = M('certificate','',C('DB2'))->where(['numbering'=>$numbering])->find();
        $lender_data = M('user','',C('DB2'))->where(['id'=>$certificate['lender_id']])->find();
        $borrower_data = M('user','',C('DB2'))->where(['id'=>$certificate['borrower_id']])->find();
        $user['lender_username'] = $lender_data['username'];
        $user['lender_identity_num'] = $lender_data['identity_num'];
        $user['lender_idcard_address'] = M('user_identity_msg','',C('DB2'))->where(['user_id'=>$certificate['lender_id']])->getField('cardaddress');
        $user['lender_mobile']=$lender_data['mobile'];
        $user['borrower_username'] = $borrower_data['username'];
        $user['borrower_identity_num'] = $borrower_data['identity_num'];
        $user['borrower_identity_address'] = M('user_identity_msg','',C('DB2'))->where(['user_id'=>$certificate['borrower_id']])->getField('cardaddress');
        $user['borrower_mobile'] = $borrower_data['mobile'];
        $user['cyear'] = date('Y',$certificate['ctime']);
        $user['cmonth'] = date('m',$certificate['ctime']);
        $user['cday'] = date('d',$certificate['ctime']);
        $user['money'] = $certificate['money'];
        $user['moneyy']=$this->cny($certificate['money']);
        switch ($certificate['loan_type']){
            case 1:
                $purpose='日常消费';
                break;
            case 2:
                $purpose ='医疗';
                break;
            case 3:
                $purpose ='旅游';
                break;
            case 4:
                $purpose ='装修';
                break;
            default:
                $purpose ='教育';
                break;
        }
        $user['purpose']=$purpose;
        $user['interest_rate']=$certificate['interest_rate'];
        $day_limit=($certificate['repayment_time']-$certificate['loan_time'])/60/60/24;
        $user['day_limit']=$day_limit<1?1:(int)$day_limit;
        $user['byear']=date('Y',$certificate['loan_time']);
        $user['bmonth']=date('m',$certificate['loan_time']);
        $user['bday']=date('d',$certificate['loan_time']);
        $user['tyear']=date('Y',$certificate['repayment_time']);
        $user['tmonth']=date('m',$certificate['repayment_time']);
        $user['tday']=date('d',$certificate['repayment_time']);
        $user['lender_signature'] = $certificate['lender_signature'];
        $user['borrower_signature'] = $certificate['borrower_signature'];
        $user['ctime'] = date('Y-m-d',$certificate['ctime']);
        $map["userName"] = $lender_data['truename'];// 用户名称 个人：姓名，机构：机构名称
        $map["userCode"] = $lender_data['id_card'];// 个人用户：身份证，机构用户：组织机构代码
        $map["userMobile"] =$lender_data['mobile'];// 用户手机
        $map["userType"] = "1";// 用户类型 1：个人，2：机构
//        $map['username'] =$userdata['truename'];
//        $map['idcard'] =$userdata['id_card'];
//        $map['mobile'] =$userdata['mobile'];
//        $map['platform'] =$userdata['truename'];
//        $map['register_time'] =date('Y-m-d H:i:s',$userdata['ctime']);
//        $map['idcard_cert_time'] =date('Y-m-d H:i:s',$userdata['ctime']);
        $map["proof_id"] = $numbering;// 用户名称 个人：姓名，机构：机构名称
        $map["borrower_name"] = $borrower_data['truename'];// 个人用户：身份证，机构用户：组织机构代码
        $map["borrower_card"] =$borrower_data['id_card'];// 用户手机
        $map["borrower_tel"] =$borrower_data['mobile'];// 用户类型 1：个人，2：机构
        $map['lender_name'] =$lender_data['truename'];
        $map['lender_card'] =$lender_data['id_card'];
        $map['lender_tel'] =$lender_data['mobile'];
        $map['money'] =$certificate['money'];
        $map['rate'] =$certificate['interest_rate'];
        $map['start_time'] =date('Y-m-d H:i:s',$lender_data['ctime']);
        $map['time_limit'] =(strtotime(date('Y-m-d',1518624000))-strtotime(date('Y-m-d',1517500800)))/60/60/24;
//        var_dump( $map['time_limit']);die;
        $map['return_time'] =date('Y-m-d',$certificate['repayment_time']);
        $map['return_type'] ='本息还款';
        $map['return_money'] =$certificate['interest'];
//        $map["itemKey"] ='I-0577003';
//        $map["flowNo"] ='X-1381001';
        $map['preserveData']=json_encode($map);

        $this->assign('data',$user); //这里加上。
        $content  = $this->fetch("ac/defer_agreement");
        $ancun    = new \Home\Service\AncunService();//A("Home/Ancun", "Service");
        $filename = '/home/wwwroot/xyc_new/b'  . time() . mt_rand(100000, 999999) . ".pdf";
        $filename = $ancun->savePdfFile($filename, $content);
        //创建pdf文件
        $ancun               = A("Home/Ancun", "Service");
        $ancun->addFile(basename($filename),dirname($filename));  //添加文件
        //创建pdf文件
        $ancun               = A("Home/Ancun", "Service");
       $res= $ancun->setData($map);
        $ancun->loanSave($map);
        $ancunOpsResponse = $ancun->save($ancun);
        unlink($filename);
        $ress = json_decode(json_encode($ancunOpsResponse),true);
        var_dump($ress);
    }
    function cny($ns) {
        static $cnums=array("零","壹","贰","叁","肆","伍","陆","柒","捌","玖"),
        $cnyunits=array("圆","角","分"),
        $grees=array("拾","佰","仟","万","拾","佰","仟","亿");
        list($ns1,$ns2)=explode(".",$ns,2);
        $ns2=array_filter(array($ns2[1],$ns2[0]));
        $ret=array_merge($ns2,array(implode("",$this->_cny_map_unit(str_split($ns1),$grees)),""));
        $ret=implode("",array_reverse($this->_cny_map_unit($ret,$cnyunits)));
        return str_replace(array_keys($cnums),$cnums,$ret);
    }
    function _cny_map_unit($list,$units) {
        $ul=count($units);
        $xs=array();
        foreach (array_reverse($list) as $x) {
            $l=count($xs);
            if ($x!="0" || !($l%4)) $n=($x=='0'?'':$x).($units[($l-1)%$ul]);
            else $n=is_numeric($xs[0][0])?$x:'';
            array_unshift($xs,$n);
        }
        return $xs;
    }
    public function borrow(){
        $vid = I('vid');
        $money = I('money');
        $rate_id = I('rate_id');
        $repayment_no = I('repayment_no');
        $userdata = M('user','',C('DB'))->where(array('vid'=>$vid))->field('truename,id_card,mobile,ctime')->find();
        $days = M('rate','',C('CAIWU'))->where(array('id'=>$rate_id))->field('type,check_rate,manage_rate,quotaaudit_rate,service_rate,invite_rate,postloanservice_rate,repay_rate')->find();
        $fee = $money*($days['check_rate']+$days['manage_rate']+$days['quotaaudit_rate']+$days['service_rate']+$days['invite_rate']+$days['postloanservice_rate']+$days['repay_rate'])/100;
        $data['fee']=$fee;
        if($rate_id==1){
            $data['lilv']=($days['check_rate']+$days['manage_rate']+$days['quotaaudit_rate']+$days['service_rate']+$days['invite_rate']+$days['postloanservice_rate']+$days['repay_rate'])*360/8;
        }else{
            $data['lilv']=($days['check_rate']+$days['manage_rate']+$days['quotaaudit_rate']+$days['service_rate']+$days['invite_rate']+$days['postloanservice_rate']+$days['repay_rate'])*360/15;
        }
        $data['borrow_day']=$days['type'];
        $cnmoney = $this->cny($money);
        $cnmoney = $cnmoney.'整';
        $data['username'] = $userdata['truename'];
        $data['id_card'] = $userdata['id_card'];
        $repay_data = M('user_repayment','',C('CAIWU'))->alias('a')->join('user_borrow b on a.borrow_no=b.borrow_no')->where(array('a.vid'=>$vid,'a.repayment_no'=>$repayment_no))->field('b.ctime,a.repay_time,b.play_account,a.repay_money,a.fee')->find();
        $data['mobile']=$userdata['mobile'];
        $data['begintime']=date('Y-m-d',$repay_data['ctime']);
        $data['finishtime']=date('Y-m-d',$repay_data['repay_time']);
        $data['cnmoney'] = $cnmoney;
        $data['year'] =date('Y',$repay_data['ctime']);
        $data['month'] =date('m',$repay_data['ctime']);
        $data['day'] = date('d',$repay_data['ctime']);
        $data['money'] = $money;
        $data['repay_money']=$money+$repay_data['fee'];
        $data['q']=substr('0'.$money,-4,1);
        $data['b']=substr('0'.$money,-3,1);
        $data['s']=substr('0'.$money,-2,1);
        $data['y']=substr('0'.$money,-1,1);
        $data['repay_year']=date('Y',$repay_data['repay_time']);
        $data['repay_month']=date('m',$repay_data['repay_time']);
        $data['repay_day']=date('d',$repay_data['repay_time']);
        $this->assign('data',$data);
        $map["userName"] = $userdata['truename'];// 用户名称 个人：姓名，机构：机构名称
        $map["userCode"] = $userdata['id_card'];// 个人用户：身份证，机构用户：组织机构代码
        $map["userMobile"] =$userdata['mobile'];// 用户手机
        $map["userType"] = "1";// 用户类型 1：个人，2：机构
        $map1['username'] =$userdata['truename'];
        $map1['idcard'] =$userdata['id_card'];
        $map1['mobile'] =$userdata['mobile'];
        $map1['borrow_money'] =$money;
        $map1['borrow_rate'] =$data['lilv'];
        $map1['borrow_day'] =$days['type'];
        $map1['repay_mode'] ='到期还款';
        $bankname = M('user_bank','',C('CWXX'))->where(array('vid'=>$vid,'bank_card'=>$repay_data['play_account']))->getField('bankname');
        $map1['receive_bank'] =$bankname;
        $map1['receive_bank_account'] =$repay_data['play_account'];
        $map1['borrow_time'] =date('Y-m-d H:i:s',$repay_data['ctime']);
        $map1['borrow_pass_time'] =date('Y-m-d H:i:s',$repay_data['ctime']);
        $map1['repay_money'] =$repay_data['repay_money']+$repay_data['fee'];
        $map1['repay_time'] =date('Y-m-d H:i:s',$repay_data['repay_time']);
        $map['preserveData']=json_encode($map1);
        $map["needInvestor"] = "true";
        $map["investorIdcard"] = "91330105328295332J";// 投资方证件号
        // 加盖借款方章(个人章)
        $map["needLender"] = "true";
        $map["lenderIdcard"] = $userdata['id_card'];// 借款方证件号
        $collaboratorIdentNos = array();
        array_push($collaboratorIdentNos, "91330303MA285LWX6R");
        // ...可添加多个合作方
        $map["collaboratorIdentNos"] = json_encode($collaboratorIdentNos);// 合作方组织机构代码
        $this->assign('data',$data); //这里加上。
        $content  = $this->fetch("template/new");
        $ancun    = new \Home\Service\AncunService();//A("Home/Ancun", "Service");
        $filename = '/usr/share/nginx/html/www/b'  . time() . mt_rand(100000, 999999) . ".pdf";
        $filename = $ancun->savePdfFile($filename, $content);
        //创建pdf文件
        $ancun               = A("Home/Ancun", "Service");
        $ancun->addFile(basename($filename),dirname($filename));  //添加文件
        $this->assign('data',$data); //这里加上。
        $content1  = $this->fetch("template/ely");
        $ancun1    = new \Home\Service\AncunService();//A("Home/Ancun", "Service");
        $filename1 = '/usr/share/nginx/html/www/a'  . time() . mt_rand(100000, 999999) . ".pdf";
        $filename1 = $ancun1->savePdfFile($filename1, $content1);
        //创建pdf文件
        $ancun               = A("Home/Ancun", "Service");
        $res=$ancun->addFile(basename($filename1),dirname($filename1));  //添加文件
        $ancun->setData($map);
        $ancun->loanSave($map);
        $ancunOpsResponse = $ancun->save($ancun);
        unlink($filename1);
        unlink($filename);
        $ress = json_decode(json_encode($ancunOpsResponse),true);
        $result=json_decode($ress['Data'],true);
        $add = array(
            'vid'=>$vid,
            'recordno'=>$result['recordNo'],//保全号
            'repayment_no'=>$repayment_no,
            'status'=>'1',
            'code'=>$ress['Code'],
            'Msg'=>$ress['Msg'],
            'ctime'=>time(),
        );
        $j=M('user_ancun_borrow','',C('DB'))->add($add);
        if($j){
            $res['ret']='1001';
            $res['code']='success';
            $res=json_encode($res);
            echo $res;
        }else{
            $res['ret']='1002';
            $res['code']='error';
            $res=json_encode($res);
            echo $res;
        }
    }
    public function borrow1(){
        $vid = '3cf407b3907b616d52c6b64e65e43c46';
        $money ='1000';
        $rate_id = '2';
        $repayment_no = I('repayment_no');
        $userdata = M('user','',C('DB'))->where(array('vid'=>$vid))->field('truename,id_card,mobile,ctime')->find();
        $days = M('rate','',C('CAIWU'))->where(array('id'=>$rate_id))->field('type,check_rate,manage_rate,quotaaudit_rate,service_rate,invite_rate,postloanservice_rate,repay_rate')->find();
        $fee = $money*($days['check_rate']+$days['manage_rate']+$days['quotaaudit_rate']+$days['service_rate']+$days['invite_rate']+$days['postloanservice_rate']+$days['repay_rate'])/100;
        $data['fee']=$fee;
        if($rate_id==1){
            $data['lilv']=($days['check_rate']+$days['manage_rate']+$days['quotaaudit_rate']+$days['service_rate']+$days['invite_rate']+$days['postloanservice_rate']+$days['repay_rate'])*360/8;
        }else{
            $data['lilv']=($days['check_rate']+$days['manage_rate']+$days['quotaaudit_rate']+$days['service_rate']+$days['invite_rate']+$days['postloanservice_rate']+$days['repay_rate'])*360/15;
        }
        $data['borrow_day']=$days['type'];
        $begintime = date('Y-m-d',time());
        $btime = explode('-', $begintime);
        $cnmoney = $this->cny($money);
        $cnmoney = $cnmoney.'整';
        $data['username'] = $userdata['truename'];
        $data['id_card'] = $userdata['id_card'];
        $repay_data = M('user_repayment','',C('CAIWU'))->alias('a')->join('user_borrow b on a.borrow_no=b.borrow_no')->where(array('a.vid'=>$vid,'a.repayment_no'=>$repayment_no))->field('b.ctime,a.repay_time,b.play_account,a.repay_money,a.fee')->find();
        $data['begintime']=date('Y-m-d',$repay_data['ctime']);
        $data['finishtime']=date('Y-m-d',$repay_data['repay_time']);
        $data['cjr']='温州日盛小额贷款有限公司';
        $data['gs']='温州众人通民间融资信息服务有限公司';
        $data['cnmoney'] = $cnmoney;
        $data['year'] = $btime['0'];
        $data['month'] = $btime['1'];
        $data['day'] = $btime['2'];
        $data['money'] = $money;
        $data['repay_money']=$money+$repay_data['fee'];
        $data['q']=substr('0'.$money,-4,1);
        $data['b']=substr('0'.$money,-3,1);
        $data['s']=substr('0'.$money,-2,1);
        $data['y']=substr('0'.$money,-1,1);
        $data['repay_year']=date('Y',$repay_data['repay_time']);
        $data['repay_month']=date('m',$repay_data['repay_time']);
        $data['repay_day']=date('d',$repay_data['repay_time']);
        $img = M('user_idcard_img','',C('DB'))->where(Array('vid'=>$vid))->getField('photo');
        $data['img']=$img;
        $this->assign('data',$data);
        $map["userName"] = $userdata['truename'];// 用户名称 个人：姓名，机构：机构名称
        $map["userCode"] = $userdata['id_card'];// 个人用户：身份证，机构用户：组织机构代码
        $map["userMobile"] =$userdata['mobile'];// 用户手机
        $map["userType"] = "1";// 用户类型 1：个人，2：机构
        $map["needInvestor"] = "true";
        $map["investorIdcard"] = "91330105328295332J";// 投资方证件号
        // 加盖借款方章(个人章)
        $map["needLender"] = "true";
        $map["lenderIdcard"] = $userdata['id_card'];// 借款方证件号
        $map1['username'] =$userdata['truename'];
        $map1['idcard'] =$userdata['id_card'];
//        $map1['email'] ='464597500@qq.com';
        $map1['mobile'] =$userdata['mobile'];
        $map1['borrow_money'] =$money;
        $map1['borrow_rate'] =$data['lilv'];
        $map1['borrow_day'] =$days['type'];
        $map1['repay_mode'] ='到期还款';
        $bankname = M('user_bank','',C('CWXX'))->where(array('vid'=>$vid,'bank_card'=>$repay_data['play_account']))->getField('bankname');
//        var_dump($bankname);die;
        $map1['receive_bank'] =$bankname;
        $map1['receive_bank_account'] =$repay_data['play_account'];
        $map1['borrow_time'] =date('Y-m-d H:i:s',$repay_data['ctime']);
        $map1['borrow_pass_time'] =date('Y-m-d H:i:s',$repay_data['ctime']);
        $map1['repay_money'] =$repay_data['repay_money']+$repay_data['fee'];
        $map1['repay_time'] =date('Y-m-d H:i:s',$repay_data['repay_time']);
        $map['preserveData']=json_encode($map1);
//        var_dump($map);die;
        $this->assign('data',$data); //这里加上。
        $content  = $this->fetch("template/new");
        $ancun    = new \Home\Service\AncunService();//A("Home/Ancun", "Service");
        $filename = '/usr/share/nginx/html/www/b'  . time() . mt_rand(100000, 999999) . ".pdf";
        $filename = $ancun->savePdfFile($filename, $content);
        //创建pdf文件
        $ancun               = A("Home/Ancun", "Service");
        $ancun->addFile(basename($filename),dirname($filename));  //添加文件
        $content1  = $this->fetch("template/ely");
        $ancun1    = new \Home\Service\AncunService();//A("Home/Ancun", "Service");
        $filename1 = '/usr/share/nginx/html/www/a'  . time() . mt_rand(100000, 999999) . ".pdf";
        $filename1 = $ancun1->savePdfFile($filename1, $content1);
        //创建pdf文件
        $ancun               = A("Home/Ancun", "Service");
        $res=$ancun->addFile(basename($filename1),dirname($filename1));  //添加文件
        $ancun->setData($map);
        $ancun->loanSave($map);
        $ancunOpsResponse = $ancun->save($ancun);
        unlink($filename1);
        unlink($filename);
        $ress = json_decode(json_encode($ancunOpsResponse),true);
        var_dump($ress);
        $result=json_decode($ress['Data'],true);
        $add = array(
            'vid'=>$vid,
            'recordno'=>$result['recordNo'],//保全号
            'repayment_no'=>$repayment_no,
            'status'=>'1',
            'code'=>$ress['Code'],
            'Msg'=>$ress['Msg'],
            'ctime'=>time(),
        );
        $j=M('user_ancun_borrow','',C('DB'))->add($add);
        if($j){
            $res['ret']='1001';
            $res['code']='success';
            $res=json_encode($res);
            echo $res;
        }else{
            $res['ret']='1002';
            $res['code']='error';
            $res=json_encode($res);
            echo $res;
        }
    }
    public function repayment(){
        $vid = I('vid');
        $repayment_no = I('repayment_no');
        $recordno=M('user_ancun_borrow','',C('DB'))->where(array('vid'=>$vid,'repayment_no'=>$repayment_no))->getField('recordno');
        if(empty($recordno)){
            $res['ret']='1002';
            $res['code']='无保全号';
            $res=json_encode($res);
            echo $res;
        }
        $userdata = M('user','',C('DB'))->where(array('vid'=>$vid))->field('truename,id_card,mobile,ctime')->find();
        $repay_data = M('user_repayment','',C('CAIWU'))->alias('a')->join('user_borrow b on a.borrow_no=b.borrow_no')->where(array('a.vid'=>$vid,'a.repayment_no'=>$repayment_no))->field('b.ctime,a.repay_time,b.play_account,a.repay_money,a.fee')->find();
//        var_dump($repay_data);
        $map["userName"] = $userdata['truename'];// 用户名称 个人：姓名，机构：机构名称
        $map["userCode"] = $userdata['id_card'];// 个人用户：身份证，机构用户：组织机构代码
        $map["userMobile"] =$userdata['mobile'];// 用户手机
        $map["userType"] = "1";// 用户类型 1：个人，2：机构
        $map["recordNo"] = $recordno;
        $map1['repay_money'] =$repay_data['repay_money']+$repay_data['fee'];
        $map1['repay_time'] =date('Y-m-d H:i:s',$repay_data['repay_time']);
        $map['preserveData']=json_encode($map1);
        $ancun    = new \Home\Service\AncunService();//A("Home/Ancun", "Service");
        $ancun->setData($map);
        $a=$ancun->repaymentSave($map);
        $ancunOpsResponse = $ancun->save($ancun);
        $ress = json_decode(json_encode($ancunOpsResponse),true);
//        var_dump($ress);
        $result=json_decode($ress['Data'],true);
        $add = array(
            'status'=>'2',
            'code'=>$ress['Code'],
            'Msg'=>$ress['Msg'],
            'ctime'=>time(),
        );
        $j=M('user_ancun_borrow','',C('DB'))->where(array('vid'=>$vid,'recordno'=>$result['recordNo']))->save($add);
        if($j){
            $res['ret']='1001';
            $res['code']='success';
            $res=json_encode($res);
            echo $res;
        }else{
            $res['ret']='1002';
            $res['code']='error';
            $res=json_encode($res);
            echo $res;
        }
    }
    public function testtb(){
        $data = M('td_tb_product_list','',C('ZHENGXIN'))->group('order_id,product_name')->limit(10)->field('order_id')->select();
        var_dump($data);
    }
}